
//valid users for PM, Corpserve and General User
var pwPM = 'passwordPM';
var userPM = 'userPM';

var userCorp = 'userCorp';
var pwCorp = 'passwordCorp';

var user = 'user';
var pw = 'password123';

$(document).ready(function () {

    $('#btnSignin').click(function () {
        var username = $("#inputEmail").val();
        var password = $("#inputPassword").val();
        var hasError = false;
        var errorMessage;
        $("#errorMessage").hide();
        if (username.length <= 0) {
            hasError = true;
            errorMessage = 'Username should not be emplty.';
            //set focus on username
            //create and display for error in username
        }

        if (password.length <= 0) {
            if (!hasError) {
                hasError = true;
                //set focus on password
                //create and display for error in password
                errorMessage = 'Password should not be empty.';
            } else {
                errorMessage = errorMessage + '</br>' + 'Password should not be empty.';
            }
        }

        if (!hasError) {
            var validUser = ValidateUser(username, password);
            if (validUser) {
                if (username == user) {
                    window.location = "../html/Dashboard.html";
                    return true;
                }
                else if (username == userPM) {
                    window.location = "../html/DashboardPM.html";
                    return true;
                }
                else if (username == userCorp) {
                    window.location = "../html/corp-dashboard-notification.html";
                    return true;
                }
            } else {
                //display error invalid username and/or password
                $("#errorMessage").html('Invalid username and/or password.');
                $("#errorMessage").slideToggle("slow");
            }
        } else {
            $("#errorMessage").html(errorMessage);
            $("#errorMessage").slideToggle("slow");
        }


    });


    $("#btnSearch").click(function () {
        var txtLength = $("#txtSearch").val().length;
        if (txtLength <= 0) {
            $("#searchError").slideToggle("slow");
        }
        else {
            window.location = "../html/search-result.html";
        }
    });

});

function ValidateUser(username, password) {
    if (username == user) {
        if (password == pw) {
            return true;
        } else {
            return false;
        }
    } else if (username == userPM) {
        if (password == pwPM) {
            return true;
        } else {
            return false;
        }
    } else if (username == userCorp) {
        if (password == pwCorp) {
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
}

  